package com.ai.dmc.utils.encryption;

/**
 * 
 * <p>
 * Title: Base64.java
 * </p>
 * <p>
 * Description: 字符串加密解密
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company: 亚信科技（中国）有限公司
 * </p>
 * <p>
 * Email to: chenhui2@asiainfo.com
 * </p>
 * 
 * @author chenhui2
 * @version 1.0
 * 
 */

public final class BASE64 {
	/**
	 * 
	 * 加密字符串
	 * 
	 * @param s
	 * @return String
	 * 
	 */
	public static String encrypt(String s) {
		if (s == null)
			return null;
		return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
	}

	/**
	 * 
	 * 解密字符串
	 * 
	 * @param s
	 * @return String
	 * 
	 */
	public static String decrypt(String s) {
		if (s == null)
			return null;
		sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
		try {
			byte[] b = decoder.decodeBuffer(s);
			return new String(b);
		} catch (Exception e) {
			return null;
		}
	}
    public static void main(String[] aa)
    {
    	String pwd1="Wangbt777";
        System.out.println(encrypt(pwd1));  //加密
        
        String pwd2="V2FuZ2J0Nzc3";
        System.out.println(decrypt(pwd2));  //解密
    }
}